package com.jiazhong.backend.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jiazhong.backend.service.UserService;
import com.jiazhong.commons.Util.JsonResult;
import com.jiazhong.commons.bean.User;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserService service;

    @RequestMapping("/page")
    public JsonResult find(@RequestParam(value = "page",defaultValue = "1") int page,@RequestParam(value = "size",defaultValue = "10") int size){
        return service.find(page,size);
    }

    @RequestMapping("/search")
    public JsonResult findSearch(@RequestParam("name") String name,
                                 @RequestParam(value = "page",defaultValue = "1") int page,
                                 @RequestParam(value = "size",defaultValue = "10") int size
                                 ){
        return service.findSearch(name, page, size);
    }

    @RequestMapping("/save")
    public JsonResult saveUser(User user){
        return service.saveUser(user);
    }

    @DeleteMapping("/remove")
    public JsonResult removeUser(@RequestParam("id") String id){
        return service.removeUser(id);
    }

    @GetMapping("/find_exists")
    public JsonResult findExists(@RequestParam("column") String column,@RequestParam("data") String data){
        return service.findExists(column, data);
    }

    @PutMapping("/update_password")
    public JsonResult updatePassword(@RequestParam("id") String id,
                                     @RequestParam("oldPass") String oldPass,
                                     @RequestParam("newPass") String newPass) {
        return service.updateUserPassword(id, oldPass, newPass);
    }
}
